﻿Public Class xSleepOpt


    Private xSleepHDAR As Microsoft.Win32.RegistryKey
    Private xRegKey As String = My.Settings.RegKey

    Private Sub xSleepOpt_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        xSleepHDAR = Microsoft.Win32.Registry.LocalMachine.OpenSubKey(xRegKey, True)
        Me.Left = xSleep.Left + 10
        Me.Top = xSleep.Top + 10

        If xSleep.xAR() Then
            AutoStartCheckBox.Checked = True
        End If

        If xSleep.xWD() Then
            WDCheckBox.Checked = True
            AltNumericUpDown.Value = xSleep.xWDAlt()
        End If

       

    End Sub

    Private Sub AutoStartCheckBox_CheckStateChanged(ByVal sender As Object, ByVal e As EventArgs) Handles AutoStartCheckBox.CheckStateChanged
        If AutoStartCheckBox.Checked = True Then
            xSleepHDAR.SetValue("xSleep", Application.ExecutablePath.ToString() & " /m")
            AutoStartCheckBox.Text = "Enabled"
            xSleep.xAR() = AutoStartCheckBox.Checked
        Else
            If AutoStartCheckBox.Checked = False Then
                xSleepHDAR.DeleteValue("xSleep", False)
                AutoStartCheckBox.Text = "Disabled"
                xSleep.xAR() = AutoStartCheckBox.Checked
            End If
        End If
    End Sub


    Private Sub CloseButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles CloseButton.Click
        Try
            xSleep.xWDAlt() = AltNumericUpDown.Value
        Catch ex As Exception
            'Nothing to see here
        End Try

        Me.Close()
    End Sub

    Private Sub WDCheckBox_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles WDCheckBox.CheckedChanged
        If WDCheckBox.Checked = True Then

            WDCheckBox.Text = "Enabled"
            AltWDLabel.Visible = True
            AltNumericUpDown.Visible = True
            AMLabel.Visible = True
            xSleepPictureBox.Image = My.Resources.alarmclock48
            xSleep.xWD() = WDCheckBox.Checked
        ElseIf WDCheckBox.Checked = False Then

            WDCheckBox.Text = "Disabled"
            AltWDLabel.Visible = False
            AltNumericUpDown.Visible = False
            AMLabel.Visible = False
            xSleepPictureBox.Image = My.Resources.alarmclock48x
            xSleep.xWD() = WDCheckBox.Checked
        End If

    End Sub

    Private Sub AltNumericUpDown_ValueChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles AltNumericUpDown.ValueChanged
        If AltNumericUpDown.Value < 6 Then
            AltNumericUpDown.Value = 6
        End If

        
    End Sub
End Class